import request from '@/utils/request';

/**
 * 分页查询用户
 */
export async function get_list(params) {
  const res = await request.post('/warehouse/goods_info/get_list', {
    ...params
  });
  if (res.data.code === 1) {
    res.data.data.columns.forEach((item) => {
      if (
        item.field == 'indexId' ||
        item.field == 'thumb_url' ||
        item.field == 'bar_code' ||
        item.field == 'type_code_name' ||
        item.field == 'location_name' ||
        item.field == 'num'
      ) {
        item.fixed = 'left';
      }
    });
    return {
      list: res.data.data.row_list,
      columns: res.data.data.columns,
      searchData: res.data.data.search_area,
      count: res.data.data.page_info?.total,
      top_button: res.data.data.top_button
    };
  }
  return Promise.reject(res.data.msg);
}

/* 调拨单详情 */
export async function goods_info(params) {
  const res = await request.post('/warehouse/goods_info/detail', params);
  if (res.data.code === 1) {
    return res.data.data;
  }
  return Promise.reject(res.data.msg);
}
/* 库存初始化 */
export async function stock_init(params) {
  const res = await request.post('/warehouse/goods_info/stock_init', params);
  if (res.data.code === 1) {
    return res.data;
  }
  return Promise.reject(res.data.msg);
}
/* 导出 */
export async function goods_info_export(params) {
  const res = await request.post('/warehouse/goods_info/export', params);
  if (res.data.code === 1) {
    return res.data.data;
  }
  return Promise.reject(res.data.msg);
}
